import { Link } from 'umi';
import { Space, Badge } from 'antd';
import { getCheckStatus } from '@/utils/Common';
import { STATIC } from '@/services/config';

export const indexColumns = [
  {
    title: '清查任务名',
    key: "name",
    dataIndex: "name",
    render: (text, row) => (
      <Link to={{ pathname: "/management/checkBook/detail", query: { id: row.id } }}>{text}</Link>
    )
  },
  {
    title: '机构名称',
    key: "unitId",
    dataIndex: "unitId"
  },
  {
    title: '学校数',
    key: "schoolNum",
    dataIndex: "schoolNum",
    align: 'center',
    sorter: (a, b) => a.schoolNum - b.schoolNum,
  },
  {
    title: '剔除书本数',
    key: "itemNum",
    dataIndex: "itemNum",
    align: 'center',
    sorter: (a, b) => a.itemNum - b.itemNum,
    multiple: 3,
  },
  {
    title: '状态',
    key: 'status',
    dataIndex: 'status',
    align: 'center',
    render: (status) => {
      const info = getCheckStatus(status);
      return <Badge status={info.badge} text={info.name} />
    },
    filters: STATIC.checkStatus.map(function (item) {
      return { text: item.name, value: item.value }
    })
  },
  {
    title: '创建时间',
    key: 'createTime',
    dataIndex: 'createTime',
    align: 'center',
    sorter: (a, b) => new Date(a.createTime).getTime() - new Date(b.createTime).getTime(),
    multiple: 1,
  },
  {
    title: '操作',
    key: 'action',
    align: 'center',
    render: (text, row) => (
      <Space size="middle">
        <Link to={{ pathname: "/management/checkBook/detail", query: { id: row.id } }}>详情</Link>
      </Space>
    )
  },
];


export const getDetailColumns = function (status = 0) {
  return status === 0 ? [
    {
      title: '机构名称',
      key: 'unitName',
      dataIndex: 'unitName'
    },
    {
      title: '机构编号',
      key: 'unitNo',
      dataIndex: 'unitNo',
      align: 'center'
    },
    {
      title: '机构类型',
      key: 'subTypeName',
      dataIndex: 'subTypeName',
      align: 'center'
    },
    {
      title: '学校类型',
      key: 'subType',
      dataIndex: 'subType',
      align: 'center'
    },
    {
      title: '所属市',
      key: 'cityName',
      dataIndex: 'cityName',
      align: 'center'
    },
    {
      title: '所属区县',
      key: 'countyName',
      dataIndex: 'countyName',
      align: 'center'
    },
    {
      title: '违禁书籍数',
      key: 'illegalNum',
      dataIndex: 'illegalNum',
      align: 'center',
      sorter: (a, b) => a.illegalNum - b.illegalNum
    },
    {
      title: '剔除数',
      key: 'rejectNum',
      dataIndex: 'rejectNum',
      align: 'center',
      sorter: (a, b) => a.rejectNum - b.rejectNum
    },
    {
      title: '完成进度',
      key: 'finishRate',
      dataIndex: 'finishRate',
      align: 'center',
      sorter: (a, b) => a.finishRate - b.finishRate,
      render(text, record) {
        return record.finishRate ? (record.finishRate * 100 + "%") : '-'
      },
    }
  ] : [{
    title: '机构名称',
    key: 'subTypeName',
    dataIndex: 'subTypeName'
  },
  {
    title: '机构类型',
    key: 'unitType',
    dataIndex: 'unitType',
    align: 'center'
  },
  {
    title: '学校类型',
    key: 'subType',
    dataIndex: 'subType',
    align: 'center'
  },
  {
    title: '所属市',
    key: 'cityName',
    dataIndex: 'cityName',
    align: 'center'
  },
  {
    title: '所属区县',
    key: 'countyName',
    dataIndex: 'countyName',
    align: 'center'
  },
  {
    title: '馆藏数',
    key: 'itemNum',
    dataIndex: 'itemNum',
    align: 'center',
    sorter: (a, b) => a.itemNum - b.itemNum
  },
  {
    title: '剔除数',
    key: 'rejectNum',
    dataIndex: 'rejectNum',
    align: 'center',
    sorter: (a, b) => a.rejectNum - b.rejectNum
  },
  {
    title: '完成时间',
    key: 'updateTime',
    dataIndex: 'updateTime',
    align: 'center',
    sorter: (a, b) => new Date(a.updateTime).getTime() - new Date(b.updateTime).getTime(),
    multiple: 1
  }]
};